package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageGroup;
import com.hunttown.mes.rpc.domain.AnalysisManageGroupDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import com.hunttown.mes.rpc.exception.ConvertException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:05:20
 */
public class AnalysisManageGroupConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageGroupConverts.class);

    public static List<AnalysisManageGroupDTO> convert(List<AnalysisManageGroup> analysisManageGroupList) {
        if (CollectionUtils.isEmpty(analysisManageGroupList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageGroupDTO> analysisManageGroupListResult = Lists.newArrayList();
        for (AnalysisManageGroup analysisManageGroup : analysisManageGroupList) {
            analysisManageGroupListResult.add(convert(analysisManageGroup));
        }
        return analysisManageGroupListResult;
    }

    public static AnalysisManageGroupDTO convert(AnalysisManageGroup analysisManageGroup) {
        try {
            return BeanUtils.copy(analysisManageGroup, AnalysisManageGroupDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageGroup到AnalysisManageGroupDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageGroup到AnalysisManageGroupDTO转换失败", e);
        }
    }

    public static AnalysisManageGroup convert(AnalysisManageGroupDTO analysisManageGroupDTO) {
        try {
            return BeanUtils.copy(analysisManageGroupDTO, AnalysisManageGroup.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageGroupDTO到AnalysisManageGroup转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageGroupDTO到AnalysisManageGroup转换失败", e);
        }
    }
}